﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace Battle
{
    public class CopyStoneBalance : MonoBehaviour
    {

        public List<GameObject> angerStones;
        public List<GameObject> fireStones;

        public UILabel angerStoneNumLabel;
        public UILabel fireStoneNumLabel;
        public UILabel angerStoneAddExpLabel;
        public UILabel fireStoneAddExpLabel;


        public void OnResultClick()
        {
            BattleManager.Instance.battlePanel.OnResultClick();
            Hide();
            Destroy(gameObject);
        }

        public void Show()
        {
            gameObject.SetActive(true);

        }

        public void Hide()
        {
            gameObject.SetActive(false);
        }

        public void Init()
        {
            ProtoBuf.Message.SCCopyFightEnd msg = StaticData.lastBattleEndMsg as ProtoBuf.Message.SCCopyFightEnd;
            if (msg != null)
            {
                angerStoneNumLabel.text = msg.dropAngerBallNum.ToString();
                fireStoneNumLabel.text = msg.dropFireBallNum.ToString();
                angerStoneAddExpLabel.text = msg.angerBallAdditionExp.ToString();
                fireStoneAddExpLabel.text = msg.fireBallAdditionCoin.ToString();

                ShowAngerStone(msg.dropAngerBallNum);
                ShowFireStone(msg.dropFireBallNum);

                // 改成都加金币了！
                StaticData.playerData.AddCoin(msg.angerBallAdditionExp);
                StaticData.playerData.AddCoin(msg.fireBallAdditionCoin);
            }
            else
            {
                angerStoneNumLabel.text = "" + 0;
                fireStoneNumLabel.text = "" + 0;
                angerStoneAddExpLabel.text = "" + 0;
                fireStoneAddExpLabel.text = "" + 0;

                ShowAngerStone(0);
                ShowFireStone(0);
            }
        }

        void ShowAngerStone(int num)
        {
            int i = 0;
            for(; i < num; ++i)
            {
                if (i < 6)
                {
                    angerStones[i].SetActive(true);
                }
            }
            for(; i < 6; ++i)
            {
                angerStones[i].SetActive(false);
            }
        }

        void ShowFireStone(int num)
        {
            int i = 0;
            for (; i < 6; ++i)
            {
                if(i < num)
                {
                    fireStones[i].SetActive(true);
                }
            }
            for(; i < 6; ++i)
            {
                fireStones[i].SetActive(false);
            }
        }


    }

}